package com.example.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.PostConstruct;
import javax.servlet.FilterRegistration;

/**
 * @Author ZHAO Yudong
 * @Date 2021/12/22 17:45
 * @description：过滤器配置
 */
@Configuration
public class MyFilterConfig {

    @PostConstruct
    public void init(){}

    @Bean
    public FilterRegistrationBean setFilter(){
        FilterRegistrationBean filterRegistration=new FilterRegistrationBean();
        MyFilter myFilter = new MyFilter();
        filterRegistration.setFilter(myFilter);
        filterRegistration.setName("myyFilter");
        filterRegistration.addUrlPatterns("/*");
        filterRegistration.setOrder(1);
        return filterRegistration;
    }

}
